package com.lightsh.joint;

import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.World;

import android.graphics.Color;

import com.lightsh.body.Circle;
import com.lightsh.body.CircleImpl;
import com.lightsh.interfaces.creator.IBodyCreator;

/**
 * 根据固定点，给一个body生成一个旋转关节
 * @author Light
 *
 */
public class FastenRevoluteJoint implements IBodyCreator{
	private Circle mFastenPoint;
	private LRevoluteJoint mRevoluteJoint;
	private World mWorld;
	private Vec2 mAnchor;
	private Body mBody;
	public FastenRevoluteJoint(World world, Body body, Vec2 anchor) {
		mWorld = world;
		mBody = body;
		mAnchor = anchor;
		// 初始化固定点得body
		mFastenPoint = new Circle(world, anchor.x, anchor.y, 0.1f, 0, 0, 0, false);
		mFastenPoint.setColor(Color.RED);
	}
	@Override
	public void create() {
		mFastenPoint.create();
		mRevoluteJoint = new LRevoluteJoint(mWorld, mBody, mFastenPoint.getBody(), mAnchor);
		mRevoluteJoint.create();
		mRevoluteJoint.mRevoluteJoint.enableMotor(true);
		mRevoluteJoint.mRevoluteJoint.setMaxMotorTorque(1000);
	}
	
	public LRevoluteJoint getJoint(){
		return mRevoluteJoint;
	}
}
